/**
 * @description parse elem html
 * @author Ling
 * @date 2024-08-08
 */

import { DOMElement } from '../dom';
import { IDomEditor, SlateDescendant, SlateElement } from '@wangeditor/editor';
import { LinkCardElement } from '../custom-types';

function parseHtml(elem: DOMElement, children: SlateDescendant[], editor: IDomEditor): SlateElement {
  const link = elem.getAttribute('data-link') || '';
  const title = elem.getAttribute('data-title') || '';
  const articleId = elem.getAttribute('data-articleId') || '';
  const linkType = elem.getAttribute('data-linkType') || '';
  return {
    type: 'link-card',
    link,
    title,
    articleId,
    linkType,
    children: [{ text: title }], // void node 必须有一个空白 text
  } as LinkCardElement;
}

const parseHtmlConf = {
  selector: 'div[data-w-e-type="link-card"]',
  parseElemHtml: parseHtml,
};

export default parseHtmlConf;
